package com.xyzboom.web.servlets.login;

import com.xyzboom.utils.VerifyCode;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import javax.imageio.ImageIO;
import java.io.IOException;

@WebServlet(urlPatterns = "/servlets/login/VerifyImage.jpg", name = "VerifyImageServlet")
public class VerifyImageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        VerifyCode verify_code = VerifyCode.getVerifyCode();
        HttpSession session = req.getSession();  //保存到session
        session.setAttribute("verify_code", verify_code);
        ImageIO.write(verify_code.getImage(), "JPG", resp.getOutputStream());
    }
}
